/*    */ package cn.com.hongpay.client.utils;
/*    */ 
/*    */ import java.io.PrintStream;
/*    */ import java.security.MessageDigest;
/*    */ import java.security.NoSuchAlgorithmException;
/*    */ 
/*    */ public class Md5Encoder
/*    */ {
/* 11 */   private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 
/* 12 */     'F' };
/*    */ 
/*    */   private static char[] encodeHex(byte[] data)
/*    */   {
/* 16 */     int l = data.length;
/*    */ 
/* 18 */     char[] out = new char[l << 1];
/*    */ 
/* 21 */     int i = 0; for (int j = 0; i < l; i++) {
/* 22 */       out[(j++)] = DIGITS[((0xF0 & data[i]) >>> 4)];
/* 23 */       out[(j++)] = DIGITS[(0xF & data[i])];
/*    */     }
/*    */ 
/* 26 */     return out;
/*    */   }
/*    */ 
/*    */   public static String encode(String rawPass)
/*    */   {
/* 32 */     MessageDigest messageDigest = getMessageDigest();
/*    */ 
/* 34 */     byte[] digest = messageDigest.digest(rawPass.getBytes());
/*    */ 
/* 36 */     return new String(encodeHex(digest)).toLowerCase();
/*    */   }
/*    */ 
/*    */   protected static final MessageDigest getMessageDigest() throws IllegalArgumentException {
/*    */     try {
/* 41 */       return MessageDigest.getInstance("MD5");
/*    */     } catch (NoSuchAlgorithmException e) {
/*    */     }
/* 44 */     throw new IllegalArgumentException("No such algorithm [MD5]");
/*    */   }
/*    */ 
/*    */   public static boolean isPasswordValid(String encPass, String rawPass)
/*    */   {
/* 49 */     String pass1 = encPass;
/* 50 */     String pass2 = encode(rawPass);
/*    */ 
/* 52 */     return pass1.equals(pass2);
/*    */   }
/*    */ 
/*    */   public static void main(String[] args)
/*    */   {
/* 57 */     String result = encode("111111");
/* 58 */     System.out.println("password=" + result);
/*    */ 
/* 60 */     boolean isGood = isPasswordValid("E10ADC3949BA59ABBE56E057F20F883E", "111111");
/* 61 */     System.out.println("isGood=" + isGood);
/*    */   }
/*    */ }

/* Location:           F:\hongpay_client.jar
 * Qualified Name:     cn.com.hongpay.client.utils.Md5Encoder
 * JD-Core Version:    0.6.0
 */